<template>
  <div>
    <el-card>

      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">主页</el-breadcrumb-item>
        <el-breadcrumb-item><a href="/goodslist">商品管理</a></el-breadcrumb-item>
      </el-breadcrumb>

      <el-table
        :data="goodslist"
        style="width: 100%">
        <el-table-column
          fixed
          prop="id"
          label="编号"
          width="80">
        </el-table-column>
        <el-table-column
          prop="goodsName"
          label="商品名称"
          width="120">
        </el-table-column>
        <el-table-column
          prop="title"
          label="商品标题"
          width="160">
        </el-table-column>
        <el-table-column
          prop="yprice"
          label="商品原价"
          width="120">
        </el-table-column>
        <el-table-column
          prop="xprice"
          label="商品秒杀价"
          width="120">
        </el-table-column>
        <el-table-column
          prop="num"
          label="商品库存"
          width="120">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="开始时间"
          width="120">
          <template slot-scope="scope">
            {{scope.row.startTime|datefmt("YYYY-MM-DD HH:mm:ss")}}
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="200">
          <template slot-scope="scope">
            <el-button @click="qianggou(scope.row.id)" type="success" plain>抢购</el-button>
          </template>
        </el-table-column>
      </el-table>
</el-card>

  </div>
</template>

<script>
  export default {
    name: 'UserList',
    data(){
      return{
        goodslist:[],
      }
    },
    methods: {
      qianggou:function(id){
        this.id = JSON.parse(sessionStorage.getItem("user")).id;
        this.$http.post('goods/grabClass?id='+this.id).then((res)=>{
          if (res.data.success) {
            this.$message({
              message: res.data.message,
              type: 'success'
            });
            this.searchList();
          }else {
            this.$message({
              message: res.data.message,
              type: 'error'
            });
          }
        })
      },
      searchList:function(){
        this.$http.post("/user/goodsList",{}).then((res)=>{
          this.goodslist = res.data.result;
        })
      },
    },
    mounted () {
      this.searchList();
    },
    filters:{
      statusFit:function(val){
        if(val==3){
          return "已发布";
        }

        return val;
      }
    }
  }
</script>

<style scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
